package com.example.drive.net.request

import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody

/**
 * POST提交json数据
 */
class JsonRequest constructor(url: String, tag: Any = Any(), private val json: String) :
    OkHttpRequest(url, tag) {
    private val requestBody by lazy {
        val contentType = "application/json;charset=utf-8".toMediaTypeOrNull()
        json.toRequestBody(contentType)
    }

    override fun createRequest(): Request {
        return builder.post(requestBody).build()
    }
}